// pages/recruit/deliveryDetail/deliveryDetail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 基本信息
    recruit_info: [],
    user_info: [],
    resume_url: '',
    resume_telephone: '',
    resume_id:'',

    // 传参
    anchor_id: '',
    recruit_id: '',
    resume_message_id: '',
    resume_id:'',

    //弹框
    flag_card: true,
  },
  //隐藏弹框
  modal_hide() {
    this.setData({
      flag_card: true,
    })
  },
  //去招聘详情
  go_detail(){
    if (this.data.status=="2"){
      wx.showToast({
        title: '审核中~',
        icon:'none',
      })
    }else{
      wx.navigateTo({
        url: '../jobDetail/jobDetail?deatil_id=' + this.data.recruit_id + "&anchor_send_resume=" + this.data.anchor_send_resume + "&check_number_real=" + this.data.check_number_real + "&share_number=" + this.data.share_number + "&status=" + this.data.status,
      })
    }
    
  },
  //卡片、电话 电话沟通
  click_talk() {
    let that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.resume_telephone,
      success(e) {
        console.log("拨打成功")
        that.send_anchor(that.data.anchor_id, that.data.recruit_id, that.data.resume_message_id, that.data.resume_id);
      }
    })
  },

  //会长沟通主播 发送请求
  send_anchor(_anchor_id, _recruit_id, _resume_message_id, resume_id) {
    wx.request({
      url: app.globalData.url + 'api/guild/link/up/anchor',
      data: {
        token: app.globalData.token,
        anchor_id: _anchor_id,
        recruit_id: _recruit_id,
        resume_message_id: _resume_message_id,
        resume_id: resume_id,
      },
      method: 'POST',
      success: function(e) {
        console.log(e.data.message)
      },
    })
  },

  // 改变查看状态请求
  commit_read(_anchor_id, _recruit_id, _resume_message_id){
    wx.request({
      url: app.globalData.url + 'api/resume/whether/check',
      data: {
        token: app.globalData.token,
        anchor_id: _anchor_id,
        recruit_id: _recruit_id,
        resume_message_id: _resume_message_id,
      },
      method: 'POST',
      success: function(e) {
        console.log(e)
      },
    })
  },


  //联系主播
  go_contact(e) {
    console.log(e)
    let that = this;

    let anchor_id = e.currentTarget.dataset.anchor_id;
    let recruit_id = e.currentTarget.dataset.recruit_id;
    let resume_message_id = e.currentTarget.dataset.resume_message_id;
    let resume_url = e.currentTarget.dataset.resume_url;
    let telephone = e.currentTarget.dataset.telephone;
    let resume_telephone = e.currentTarget.dataset.resume_telephone; //简历电话
    let resume_id = e.currentTarget.dataset.resume_id

    this.setData({
      anchor_id: anchor_id,
      recruit_id: recruit_id,
      resume_message_id: resume_message_id,
      resume_url: resume_url,
      telephone: telephone,
      resume_id : e.currentTarget.dataset.resume_id,
      resume_telephone: resume_telephone, //简历电话
      resume_id: resume_id,
    })

    this.commit_read(this.data.anchor_id, this.data.recruit_id, this.data.resume_message_id);
    this.get_detailInfo(this.data.recruit_id);


    if (telephone == "") {
      this.setData({
        // flag_card: false,
        // resume_url: resume_url,
      })
      wx.navigateTo({
        url: '../singleRecruit/singleRecruit?resume_id=' + resume_id + '&anchor_id=' + that.data.anchor_id + '&resume_message_id=' + that.data.resume_message_id + '&recruit_id=' + that.data.recruit_id,
      })
    } else {
      wx.showModal({
        content: 'ta给您留了电话,马上撩一下',
        confirmText:"立即沟通",
        confirmColor:"#d0a76c",
        success(e){
          // console.log(e.confirm)
          if (e.confirm){
            wx.makePhoneCall({
              phoneNumber: telephone,
              success(e) {
                console.log("拨打成功")
                that.send_anchor(this.data.anchor_id, this.data.recruit_id, this.data.resume_message_id, this.data.resume_id);
              }
            })
          }
          
        }
      })
      
    }

  },


  //获取详情信息
  get_detailInfo(_recruit_id) {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/acquirement/anchor/detail',
      data: {
        token: app.globalData.token,
        recruit_id: _recruit_id,
      },
      method: 'POST',
      success: function(e) {
        console.log(e.data.data)
        let recruit_info = e.data.data.recruit;
        let user_info = e.data.data.userInfo;
        that.setData({
          recruit_info: recruit_info,
          user_info: user_info,

          //设置
          anchor_send_resume: e.data.data.recruit.anchor_send_resume,
          check_number_real: e.data.data.recruit.check_number_real,
          share_number: e.data.data.recruit.share_number,
          status: e.data.data.recruit.status,

          //预置
          resume_message_id: e.data.data.userInfo[0].resume_message_id,
          recruit_id: e.data.data.userInfo[0].recruit_id,
          anchor_id: e.data.data.userInfo[0].anchor_id,
          resume_id: e.data.data.userInfo[0].resume_id,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    if (options.recruit_id) {
      this.setData({
        recruit_id: options.recruit_id,
      })
    }
    this.get_detailInfo(this.data.recruit_id);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})